﻿#region 命名空间

using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

using Sharp.Domain.CMSBoundedContext.VIUModule.Aggregates;
using Sharp.Domain.Model;

#endregion

namespace Sharp.Domain.CMSBoundedContext.ModelConfigurations
{
    /// <summary>
    ///     Represents the entity type configuration for the <see cref="VIUCategory" /> entity.
    /// </summary>
    public partial class CategoryTypeConfiguration : EntityTypeConfiguration<VIUCategory>
    {
        #region 构造函数

        /// <summary>
        ///     Initializes a new instance of <c>CustomerTypeConfiguration</c> class.
        /// </summary>
        public CategoryTypeConfiguration()
        {
            HasKey(c => c.Id);
            Property(t => t.Id)
                           .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)
                           .IsRequired();
            Property(t => t.Name)

                .HasMaxLength(50)
                .IsOptional();
 
            Property(t => t.ParentId)

                .IsOptional();
            Property(t => t.OrderId)

                .IsRequired();

            this.HasOptional(t => t.Parent)
           .WithMany(t => t.Children)
           .HasForeignKey(d => d.ParentId);

            this.HasMany(x => x.Tags)
                .WithOptional(x => x.Category)
                .HasForeignKey(x => x.CategoryId);
        }

        #endregion
    }
}